$(window).load(function(){
    
    // ieCheck
    var ie = false;
    var aniButtonDuration = 350;
	 var defMh = 0, h = 0;
	 defMh = parseInt($('body').css('minHeight'));
     var MSIE = ($.browser.msie) && ($.browser.version <= 8)
    
    if($.browser.msie && $.browser.version<9)
    {
        aniButtonDuration = 0;
        ie = true;
    }
    
     
    
    $('.gall_spinner').hide();
    $('#bgStretch')
		.bgStretch({
			align:'rightTop',
			navigs:$('#bgNav').navigs({prevBtn:$('#prev_arr'), nextBtn:$('#next_arr')})
		}).sImg({
			spinner:$('.gall_spinner')
		}) 
        
    $('#prev_arr, #next_arr')
	.sprites({
		method:'simple',
		duration:400,
		easing:'easeOutQuint',
		hover:true
	})
        
	 
	 //follow-icons-------------	 
   $('.follow-icon .img_act').css({opacity:0})
	$('.follow-icon a').hover(function(){
		$(this).find('.img_act').stop().animate({opacity:1})
      $(this).find('p').stop().animate({color:'#000'}, 550, 'easeOutSine')						 
	}, function(){
		$(this).find('.img_act').stop().animate({opacity:0})
      $(this).find('p').stop().animate({color:'#1E1E1E'}, 550, 'easeOutSine')							 
	})
	




    // scroller
    $('.scroll')
        .uScroll({
            axis:'x'
            ,lay:'outside'
            ,duration:600
            ,easing:'easeInOutSine'
            ,step:100
            ,mousewheel:true
        })
        
        $('._shuttle').mouseover(
        function(){
            $(this).stop().animate({'opacity':'1'},500,'easeOutExpo');
        })
        $('._shuttle').mouseout(
          function(){
            $(this).stop().animate({'opacity':'1'},500,'easeOutExpo');
        })


        if(!MSIE){ $('._thumbList >li>a, #page_portfolio a').find(".zoomSp1").fadeTo(500, 0)}else{ $('._thumbList >li>a, #page_portfolio a').find(".zoomSp1").css({"display":"none"})  }
         $('._thumbList > li a, #page_portfolio a').hover(
         function(){
             $(this).find(".zoomSp1").stop().fadeTo(500, 1)
         },
         function(){
               $(this).find(".zoomSp1").stop().fadeTo(500, 0)
            }
         )  
    //end scroller

     /*FANCYBOX*/  
    $("a[rel=Appendix]").fancybox({
        'transitionIn'      : 'elastic',
        'transitionOut'     : 'elastic',
        'titlePosition'     : 'over',
        'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
        return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });

    $("a[rel=index]").fancybox({
        'transitionIn'      : 'elastic',
        'transitionOut'     : 'elastic',
        'titlePosition'     : 'over',
        'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
        return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });


    /////////////////////////////////////////////////////////////////////////// 
    //                           content switch                              //
    ///////////////////////////////////////////////////////////////////////////
    
    var content=$('#content'),
        nav=$('.menu'),
        spot_splash=$('#spot_splash'),
        spot_content=$('#spot_content'),
        header=$('header'),
        splash = $('#splash'),
        height_ofset=0;
    
    $('ul#menu').superfish({
      delay:       700,
      animation:   {height:'show'},
      speed:       300,
      autoArrows:  false,
      dropShadows: false
    });

    $('.submenu_1 a b').css({width:'0px'})
    $('.submenu_1 a').hover(function()
    {
        $(this).find('b').css({width:'0px', left:'0px'}).stop().animate({width:'100%'}, 300,'easeOutCubic');			   
    }, function(){
        $(this).find('b').stop().animate({width:'0px', left:'119px'}, 300,'easeOutCubic');						   
    })
    
    
    nav.navs({
		useHash:true,
        defHash:'#!/',
		hoverIn:function(li){
		   	  $('>a ',li).css({color:'#fff'});
		   	  $('> a > span ',li).css({display:'block'}).stop().animate({opacity:1}, aniButtonDuration, 'easeOutCubic');
		},
		hoverOut:function(li){
		  if (!li.hasClass('with_ul') || !li.hasClass('sfHover')) {
              $('>a ',li).css({color:'#383c3f'});
		   	  $('> a > span ',li).stop().animate({opacity:0}, aniButtonDuration, 'easeOutCubic', function(){
		   	      $(this).css({display:'none'});
		   	  });
          }
		}				
    })
    
	 
	 $(window).resize(function (){
		 if (h < defMh) {h = defMh}
		 $('body').stop().animate({'minHeight':h})
         var top_value;
         top_value=$(window).height()-h-50-height_ofset;
         if(top_value<30) {top_value=30}
         header.css({'margin-bottom':top_value+'px'});

		});
		
		
     content.tabs({
		preFu:function(_)
        {
            _.li.css({display:'none', top:'620px'});
            _.li.each(function(){
                if($(this).height() < 553){
                    $(this).height(553);
                } else {
                    $(this).height($(this).height()+0)
                }
            })
		}
		,actFu:function(_)
        {

            if(_.pren == undefined){
                aniDelay = 250;
            } else {
                if(_.n == -1 && _.pren == -1){
                    aniDelay = 250;
                } else {
                    aniDelay = 450;
                }
            }

            var customStep = function() {
                content.css({overflow:'visible'})
            }
            
            if(_.n == -1){
                height_ofset=40;
                content.stop().delay(400).animate({height:'578px'}, {step:customStep}, 550,'easeOutCubic');
                splash.css({display:'block'}).stop().delay(aniDelay).animate({top:'0px'}, 650, 'easeOutQuint');
                spot_splash.stop().delay(aniDelay).animate({opacity:1}, 650, 'easeOutQuint');
                spot_content.stop().delay(aniDelay).animate({opacity:0}, 650, 'easeOutQuint');

                    h=578;
					$(window).trigger('resize');
            } else {
                height_ofset=0;
                /*content.stop().delay(0).animate({height:_.curr.height()+30}, 250,'easeOutCubic');*/
                content.stop().delay(400).animate({height:_.curr.height()+0}, {step:customStep}, 550,'easeOutCubic');
                spot_splash.stop().delay(aniDelay).animate({opacity:0}, 650, 'easeOutQuint');
                spot_content.stop().delay(aniDelay).animate({opacity:1}, 650, 'easeOutQuint');
                splash.stop().animate({top:'1120px'}, 350, 'easeInCubic', function(){
                    $(this).css({display:'none'});
                });
            }
            
        	if(_.curr){
        	   h = parseInt( _.curr.outerHeight(true)+250);
				$(window).trigger('resize');
				_.curr
					.stop()
					.delay(aniDelay).css({display:'block', top:-content.height()-500}).animate({top:'0px'}, 650,'easeOutCubic');
            }

            
			if(_.prev){
			    _.prev 
    				.stop()
    				.animate({top:content.height()+500}, 350,'easeInSine', function(){
    				     $(this).css({display:'none'});
    			     });
            }
           
        }
		
	})
       
    nav.navs(function(n, _)
    {
		content.tabs(n);
	})
    
 
})